package com.xomily.devops.service.impl;

import java.util.List;
import com.xomily.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xomily.devops.mapper.DevNetMapper;
import com.xomily.devops.domain.DevNet;
import com.xomily.devops.service.IDevNetService;

/**
 * 网络IO运维日志Service业务层处理
 * 
 * @author xomily
 * @date 2021-11-29
 */
@Service
public class DevNetServiceImpl implements IDevNetService 
{
    @Autowired
    private DevNetMapper devNetMapper;

    /**
     * 查询网络IO运维日志
     * 
     * @param id 网络IO运维日志主键
     * @return 网络IO运维日志
     */
    @Override
    public DevNet selectDevNetById(Long id)
    {
        return devNetMapper.selectDevNetById(id);
    }


    /**
     * 查询网络IO运维日志列表
     * 
     * @param devNet 网络IO运维日志
     * @return 网络IO运维日志
     */
    @Override
    public List<DevNet> selectDevNetList(DevNet devNet)
    {
        return devNetMapper.selectDevNetList(devNet);
    }

    
    /**
     * 新增网络IO运维日志
     * 
     * @param devNet 网络IO运维日志
     * @return 结果
     */
    @Override
    public int insertDevNet(DevNet devNet)
    {
    	DevNet netQuery = new DevNet();
        netQuery.setIp(devNet.getIp());
        netQuery.setName(devNet.getName());
        DevNet net=devNetMapper.selectDevNetByIpName(netQuery);
        if (net != null) {
            devNet.setId(net.getId());        	
            devNet.setUpdateTime(DateUtils.getNowDate());
            return devNetMapper.updateDevNetByInfo(devNet);
        } else {
            devNet.setCreateTime(DateUtils.getNowDate());
            return devNetMapper.insertDevNet(devNet);        	
        }
    }

    /**
     * 修改网络IO运维日志
     * 
     * @param devNet 网络IO运维日志
     * @return 结果
     */
    @Override
    public int updateDevNet(DevNet devNet)
    {
        devNet.setUpdateTime(DateUtils.getNowDate());
        return devNetMapper.updateDevNet(devNet);
    }

    /**
     * 批量删除网络IO运维日志
     * 
     * @param ids 需要删除的网络IO运维日志主键
     * @return 结果
     */
    @Override
    public int deleteDevNetByIds(Long[] ids)
    {
        return devNetMapper.deleteDevNetByIds(ids);
    }

    /**
     * 删除网络IO运维日志信息
     * 
     * @param id 网络IO运维日志主键
     * @return 结果
     */
    @Override
    public int deleteDevNetById(Long id)
    {
        return devNetMapper.deleteDevNetById(id);
    }
}
